package com.backend.securitiessystem.service.impl;

import com.backend.securitiessystem.dao.IIndexDao;
import com.backend.securitiessystem.dto.IndexDto;
import com.backend.securitiessystem.pojo.Index;
import com.backend.securitiessystem.service.IndexService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

/**
 * 索引服务导入
 *
 * @author LWY
 * @date 2024-05-23 03:38:23
 */
@Service
public class IndexServiceImpl extends ServiceImpl<IIndexDao, Index> implements IndexService {

    @Override
    public IPage<IndexDto> selectPageWithCondition(int current, int size, QueryWrapper<Index> queryWrapper) {
        Page<Index> page1 = new Page<>(current, size);
        IPage<Index> indexDtoIPage = this.page(page1, queryWrapper);

        List<IndexDto> indexDtos = new ArrayList<>();
        for (Index index : indexDtoIPage.getRecords()) {
            IndexDto indexDto = new IndexDto();
            indexDto.setName(index.getName());
            indexDto.setLatestPrice(index.getLatestPrice());
            indexDtos.add(indexDto);
        }
        IPage<IndexDto> indexDtoIPage1 = new Page<>();
        indexDtoIPage1.setRecords(indexDtos);
        indexDtoIPage1.setSize(size);
        indexDtoIPage1.setCurrent(current);
        indexDtoIPage1.setTotal(indexDtoIPage.getTotal());
        return indexDtoIPage1;
    }
}
